package com.zmc.lostfound.common.utils;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

/**
 * @author ZMC
 * @description MD5盐值加密工具类
 */
public class Md5Util {

    private static final BCryptPasswordEncoder B_CRYPT_PASSWORD_ENCODER = new BCryptPasswordEncoder();

    /**
     * 密码加密
     *
     * @param password 明文密码
     * @return 加密字符串
     */
    public static String encryption(String password) {
        return B_CRYPT_PASSWORD_ENCODER.encode(password);
    }

    /**
     * 校验密码是否正确
     *
     * @param loginPassword 明文密码
     * @param cryptPassword 正确密码的加密字符串
     * @return true:正确, false:错误
     */
    public static boolean checkPassword(String loginPassword, String cryptPassword) {
        return B_CRYPT_PASSWORD_ENCODER.matches(loginPassword, cryptPassword);
    }

}
